﻿@model indicadores.Models.Login
@{
    ViewBag.Title = "Novo";
    Layout = "~/Views/Shared/Layout.cshtml";
}
@section Head{
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/Cadastro.css")" rel="stylesheet" type="text/css" />
    <style>
        table
        {
            border: 1px solid #ccc;
        }
        #Conteudo
        {
            padding-top: 0px;
        }
        fieldset
        {
            margin-top: 20px;
        }
    </style>
    <link href="@Url.Content("~/Content/Impromptu.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-impromptu.3.1.min.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var urli = '@Url.Action("Apagar", "Login")';
        $(document).ready(function () {
            $(".apagar").click(function () {
                var id = $(this).attr('id');
                $.prompt('Tem certeza que deseja remover este usuário?', { buttons: { Sim: true, Não: false }, focus: 1, callback: function (v, m, f) {
                    if (v) {
                        $.ajax({
                            url: urli + '/' + id,
                            success: function (retorno) {
                                $("#" + id).hide('slow', function () { $(this).remove(); });
                                $.prompt(retorno);
                            },
                            error: function (retorno) {
                                $.prompt(retorno);
                            }
                        });
                    }
                    else {
                    }
                }
                });
            });
        });
    </script>
}
@section SubMenu{
    <h1>
        Usuários Com Acesso</h1>
}
<table>
    <tr>
        <th>
            Nome
        </th>
        <th>
            Usuario
        </th>
        <th>
            Acesso
        </th>
        <th>
        </th>
    </tr>
    @{
        ICollection<indicadores.Models.Login> l = new indicadores.Models.DepartamentoRepositorio().Busca(Convert.ToInt32(Request.RawUrl.ToString().Split('/')[3])).Usuarios;    
    }
    @foreach (var item in l)
    {
        <tr id="@item.Id">
            <td>
                @Html.DisplayFor(modelItem => item.Nome)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Usuario)
            </td>
            @if (Html.DisplayFor(modelItem => item.Acesso).ToString() == "0")
            {
                <td>
                    Administrador
                </td>
            }
            @if (Html.DisplayFor(modelItem => item.Acesso).ToString() == "1")
            {
                <td>
                    Usuário Comum
                </td>
            }
            <td>
                <a href="#" class="apagar" id="@item.Id">Remover</a>
            </td>
        </tr>
    }
</table>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>
            <h2>
                Conceder Acesso</h2>
        </legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.Nome)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Nome)
            @Html.ValidationMessageFor(model => model.Nome)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Usuario)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Usuario)
            @Html.ValidationMessageFor(model => model.Usuario)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Acesso)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.Acesso, new indicadores.Models.Acesso().Lista())
            @Html.ValidationMessageFor(model => model.Acesso)
        </div>
        <div class="editor-label">
            <input type="submit" name="Acesso" value="Conceder Acesso" />
        </div>
    </fieldset>
}
@Html.ActionLink("Voltar", "Detalhes", new { id = Convert.ToInt32(Request.RawUrl.Split('/')[3]) })
